package us.versus.them.b3ge;

import flash.display.DisplayObject;
import flash.display.BitmapData;

import flash.text.TextField;

class Util {

	public static function displayObjectForName( name:String ) : DisplayObject {
		var cl = Type.resolveClass( name );
		return ( cast( Type.createInstance( cl, [] ), DisplayObject ) );
	}

	public static function bitmapDataForName( name:String ) {
		return displayObjectToBitMapData( displayObjectForName( name ) );
	}

	public static function displayObjectToBitMapData( displayObject:DisplayObject ) {
		var bitmapData = new BitmapData( 
				Math.floor( displayObject.width  )
				, Math.floor( displayObject.height )
				, true
				, 0x0
				);
		bitmapData.draw( displayObject );
		return bitmapData;
	}

	/* this text field sort of looks like a button... if you squint... */
	public static function buttonish( text:String ) : TextField {
		var txt = txt( text );
		txt.background = txt.border = true;
		txt.backgroundColor = 0xAAAAEE;
		txt.borderColor = 0;
		txt.height = 18;
		return txt;
	}

	public static function txt( text:String ) : TextField {
		var txt = new TextField();
		txt.text = text;
		txt.selectable = false;
		txt.autoSize = flash.text.TextFieldAutoSize.LEFT;
		return txt;
	}
}
